package top.jolyoulu.corecommon.autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.jolyoulu.corecommon.cache.LocalCacheOperator;
import top.jolyoulu.corecommon.cache.def.DefaultLocalCacheBootStrap;
import top.jolyoulu.corecommon.cache.def.DefaultLocalCacheEvictPolicy;
import top.jolyoulu.corecommon.cache.def.DefaultLocalCacheOperator;

/**
 * @Author: JolyouLu
 * @Date: 2024/2/4 17:05
 * @Description
 */
@Configuration
public class DefaultCacheAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(LocalCacheOperator.class)
    public DefaultLocalCacheOperator defaultLocalCacheOperator() {
        return new DefaultLocalCacheOperator(100);
    }

    @Bean
    @ConditionalOnMissingBean(DefaultLocalCacheEvictPolicy.class)
    public DefaultLocalCacheEvictPolicy defaultLocalCacheEvictPolicy() {
        return new DefaultLocalCacheEvictPolicy();
    }

    @Bean
    public DefaultLocalCacheBootStrap delayedTaskConsumer(DefaultLocalCacheOperator defaultCacheOperator,
                                                          DefaultLocalCacheEvictPolicy defaultLocalCacheEvictPolicy) {
        return new DefaultLocalCacheBootStrap(defaultCacheOperator, defaultLocalCacheEvictPolicy);
    }
}
